<script setup>
	import FirstTitle from "@comp/FirstTitle";
	import {
		Editor,
		Toolbar
	} from "@wangeditor/editor-for-vue";
	import {
		onMounted
	} from "vue";

	import {
		postTableData
	} from "@/api/table";

	import {
		searchDataZhbz
	} from "@/api/search";
	import {
		addOrUpdateZhbz
	} from "@/api/addOrUpdate";


	const city = window.globalObj.name;


	const editorRef = shallowRef();
	const toolbarConfig = {};
	const editorConfig = {
		placeholder: "请输入内容..."
	};
	const mode = ref("default");

	// 加载html
	const initHtml = () => {
		searchDataZhbz({
			m: "能力现状-医疗救护能力现状"
		}).then((res) => {
			const {
				data
			} = res
			valueHtml.value = data.find((x) => x.k === "医疗救护能力现状")?.v || "";
		})
	};

	const handleCreated = (editor) => {
		editorRef.value = editor; // 记录 editor 实例，重要！
	};

	const valueHtml = ref(
		"共有医院XX所、共有医护人员XX人。具体情况如下："
	);

	const saveProgramme = () => {
		ElMessageBox.confirm(`确定要保存吗?`, "警告", {
			confirmButtonText: "确定",
			cancelButtonText: "取消",
			type: "warning",
			customClass: "message-box",
		}).then(() => {
			addOrUpdateZhbz({
					m: "能力现状-医疗救护能力现状",
					data: [{
						k: "医疗救护能力现状",
						v: valueHtml.value,
					}],
				})
				.then((result) => {
					if (result.code === 200) {
						ElMessage.success("操作成功");
						initHtml();
					} else {
						ElMessage.error(result.msg);
					}
				})
				.catch(() => {});
		});
	}


	onBeforeUnmount(() => {
		const editor = editorRef.value;
		if (!editor) return;
		editor.destroy();
	});



	// 表头单元格样式
	const headerCellStyle = () => {
		return {
			backgroundColor: "#f5f7fa",
			color: "rgba(0,0,0,0.85)",
			fontSize: "14px",
			height: "54px",
		};
	};
	// 单元格样式
	const cellStyle = () => {
		return {
			color: "rgba(0,0,0,0.65)",
			fontSize: "14px",
			lineHeight: "22px",
		};
	};

	const tableData = ref([])
	const getList = () => {
		postTableData({
			docType: "comprehensiveSupport",
			method: "yihurenyuanqingkuangtongji",
		}).then(result => {
			if (result.code === 200) {
				tableData.value = result.data
			}
		})
	}

	onMounted(() => {
		initHtml()
		getList()
	})
</script>
<template>
	<div class="">
		<FirstTitle name="医疗救护能力现状" />
		<div style="border: 1px solid #ccc" class="top-15">
			<Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRef" :defaultConfig="toolbarConfig"
				:mode="mode" />
			<Editor style="height: 500px; overflow-y: hidden" v-model="valueHtml" :defaultConfig="editorConfig"
				:mode="mode" @onCreated="handleCreated" />
		</div>
		<!-- <div class="top-15">
			
		</div> -->
		<div class="top-15 text-center">
			{{city}}医院、医护人员情况统计表
		</div>
		<el-table id="table" :data="tableData" class="top-15" style="width: 100%" :header-cell-style="headerCellStyle"
			:cell-style="cellStyle" border>
			<el-table-column prop="rowNum" label="序号" width="100" align="center" />
			<el-table-column prop="jd_name" label="行政区域" />
			<el-table-column prop="c3" label="卫生机构数量">
				<el-table-column prop="sum" label="总数" />
				<el-table-column prop="hospital_sum" label="医院" />
				<el-table-column prop="jc_hospiatl" label="基层医疗卫生机构" />
				<el-table-column prop="zy_sanitation" label="专业公共卫生机构" />
				<el-table-column prop="other_sanitation" label="其他卫生机构" />
			</el-table-column>
			<el-table-column prop="c3" label="卫生技术人员">
				<el-table-column prop="wsjsrssl" label="卫生技术人员" />
				<el-table-column prop="physician" label="执业（助理）医师" />
				<el-table-column prop="nurse" label="注册护士" />
			</el-table-column>
			<el-table-column prop="c3" label="床位数">
				<el-table-column prop="bedroom" label="床位数" />
				<el-table-column prop="yscwsl" label="医院床数" />
				<el-table-column prop="jcwsjgcwsl" label="基层卫生机构" />
				<el-table-column prop="zywsjgcwsl" label="专业卫生机构" />
			</el-table-column>
		</el-table>

		<div class="flex-justify-end top-20">
			<el-button type="primary" class="save-btn" @click="saveProgramme">保存</el-button>
		</div>
	</div>
</template>
<style scoped lang="scss"></style>